<template>
  <div class="base-container">
    <t-form ref="form" :data="queryParams" label-width="80" @submit="()=>{this.queryParams.pageNum=1;this.pagination.current=1;this.getList()}"
            @reset="()=>{this.queryParams.pageNum=1;this.pagination.current=1;this.getList()}">
      <t-row style="border-bottom: 1px solid #E5E6EB;margin-bottom: 10px">
        <t-col :span="11" class="query-form-inline">
                    <t-form-item label="标题" name="title">
                      <t-input
                        v-model="queryParams.title"
                        clearable
                        placeholder="请输入标题"
                        style="width: 240px"
                      />
                    </t-form-item>
                    <t-form-item label="状态" name="status">
                      <t-select style="width: 240px" placeholder="状态" :options="dict.type.sys_problem_status"
                                v-model="queryParams.status"></t-select>
                    </t-form-item>
        </t-col>
        <t-col :span="1" class="operation-container">
          <t-button theme="primary" type="submit">查询</t-button>
          <t-button theme="default" variant="outline" type="reset">重置</t-button>
        </t-col>
      </t-row>
    </t-form>
    <t-table
      rowKey="id"
      :data="data"
      :columns="columns"
      hover
      :pagination="pagination"
      :loading="dataLoading"
    >
      <template #sort="{rowIndex}">
        {{ rowIndex+1 }}
      </template>
      <template #status="{row}">
        <t-tag   class="cursor-pointer" :theme="handleTheme(row.status, dict.type.sys_problem_status)" variant="light">
          {{ row.status | filterByDict(dict.type.sys_problem_status) }}
        </t-tag>
      </template>
      <template #content="{row}">
<!--        <div v-html="row.content"></div>-->
        <inner-html :content="row.content"></inner-html>

      </template>
      <template #op="{ row }">
                <t-button @click="dialog.header='回复记录';dialog.objId=row.id;dialog.open = true;" size="small"
                          variant="text" class="t-button-link">
                  <t-icon name="info-circle" slot="icon"/>
                  回复记录
                </t-button>
        <t-button @click="dialog.header='详情';dialog.disabled=true;dialog.objId=row.id;dialog.openDetail = true;" size="small"
                  variant="text" class="t-button-link">
          <t-icon name="info-circle" slot="icon"/>
          详情
        </t-button>
      </template>
    </t-table>
    <feedback-reply-index :header="dialog.header" ref="feedback-reply-index" :visible.sync="dialog.open"
                          v-if="dialog.open" replyType="2" :objId="dialog.objId"></feedback-reply-index>

    <add-edit-feed-back :disabled="dialog.disabled" @reload="getList()" reply-type="2" :header="dialog.header" :objId="dialog.objId" :visible.sync="dialog.openDetail"
                        v-if="dialog.openDetail"></add-edit-feed-back>
  </div>
</template>

<script>
import addEditFeedBack from "./components/add-edit-feedback.vue";
import feedbackReplyIndex from "./feedback-reply-index.vue";
import InnerHtml from "@/components/InnerHtml/index.vue";


export default {
  name: "feedback-index",
  dicts: ['sys_problem_status'],
  components:{
    addEditFeedBack,
    feedbackReplyIndex,
    InnerHtml
  },
  data(){
    return {
      dialog:{
        header: '',
        objId: null,
        open: false,
        status: '',
        openDetail: false,
        disabled: false
      },
      data: [],
      columns: [
        {
          colKey: "sort",
          title: "序号",
          align: "center",
          width: 60
        },
        {
          colKey: "title",
          title: "标题",
          align: "center",
        },
        // {
        //   colKey: "content",
        //   title: "内容",
        //   align: "center",
        // },
        {
          colKey: "status",
          title: "状态",
          align: "center",
          width: 100
        },
        {
          colKey: "createTime",
          title: "创建时间",
          align: "center",
          width: 180
        },
        {
          colKey: "op",
          title: "操作",
          align: "center",
          width: 180
        },
      ],
      dataLoading: false,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        title: '',
      },
      pagination: {
        current: 1,
        pageSize: 10,
        total: 0,
        showPageSize: true,
        pageSizeOptions: [10, 20, 30, 50],
        showFirstAndLastPageBtn: false,
        onChange: (pageInfo) => {
          Object.assign(this.pagination,pageInfo)
          this.queryParams.pageNum = pageInfo.current || 1;
          this.queryParams.pageSize = pageInfo.pageSize;
          this.getList()
        },
      },
    }
  },
  created(){
    this.getList();
  },
  methods:{
    getList(){
      this.dataLoading = true;
      this.$api.system.feedback.list(this.queryParams).then(response => {
        this.pagination.total = response.total;
        this.data = response.rows;
        this.dataLoading = false;
      }).catch((e) => {
        this.dataLoading = false;
        this.$message.error(e.toString());
      });
    },
  }
}
</script>

<style scoped>

</style>
